package com.czl.base.event

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.czl.base.config.ComplaintType
import com.czl.base.config.OrderType
import com.czl.base.data.bean.MembersBean
import com.czl.base.data.bean.TodoBean
import com.czl.base.data.bean.tengyun.AssetHandleFacilityBean
import com.czl.base.data.bean.tengyun.PurchaseOrderBean
import com.czl.base.data.bean.tengyun.AssetHandleSortBean
import com.czl.base.data.bean.tengyun.SortBean
import com.jeremyliao.liveeventbus.LiveEventBus

/**
 * @author Alwyn
 * @Date 2020/10/16
 * @Description 事件分发中心管理
 * 可通过Kotlin的命名可选参数特性 一个方法即可判断 发送/接收
 * sticky : post/observeSticky
 */
object LiveBusCenter {

//    fun handleMainEvent(
//        value: String? = null,
//        owner: LifecycleOwner? = null,
//        observer:Observer<MainEvent>?=null
//    ) {
//        if (null == owner && value != null) {
//            LiveEventBus.get(MainEvent::class.java).post(MainEvent(value))
//            return
//        }
//        owner?.let{
//            observer?.apply {
//                LiveEventBus.get(MainEvent::class.java).observe(it, this)
//            }
//        }
//    }


    fun postScoreCompleteEvent() {
        LiveEventBus.get(ScoreCompleteEvent::class.java).post(ScoreCompleteEvent(""))
    }

    fun observeScoreCompleteEvent(owner: LifecycleOwner, func: (t: ScoreCompleteEvent) -> Unit) {
        LiveEventBus.get(ScoreCompleteEvent::class.java).observe(owner, Observer(func))
    }

    fun postTakeSuccessEvent(orderType: OrderType) {
        LiveEventBus.get(TakeSuccessEvent::class.java).post(TakeSuccessEvent(orderType))
    }

    fun observeTakeSuccessEvent(owner: LifecycleOwner, func: (t: TakeSuccessEvent) -> Unit) {
        LiveEventBus.get(TakeSuccessEvent::class.java).observe(owner, Observer(func))
    }

    fun postRefreshComplaintEvent(complaintType: ComplaintType) {
        LiveEventBus.get(RefreshComplaintEvent::class.java).post(RefreshComplaintEvent(complaintType))
    }

    fun observeRefreshComplaintEvent(owner: LifecycleOwner, func: (t: RefreshComplaintEvent) -> Unit) {
        LiveEventBus.get(RefreshComplaintEvent::class.java).observe(owner, Observer(func))
    }

    fun postLogoutEvent() {
        LiveEventBus.get(LogoutEvent::class.java).post(LogoutEvent(0))
    }

    fun observeLogoutEvent(owner: LifecycleOwner, func: (t: LogoutEvent) -> Unit) {
        LiveEventBus.get(LogoutEvent::class.java).observe(owner, Observer(func))
    }

    fun postSetPwdEvent() {
        LiveEventBus.get(SetPwdEvent::class.java).post(SetPwdEvent(0))
    }

    fun observeSetPwdEvent(owner: LifecycleOwner, func: (t: SetPwdEvent) -> Unit) {
        LiveEventBus.get(SetPwdEvent::class.java).observe(owner, Observer(func))
    }

    fun postPayResultEvent(code: Int) {
        LiveEventBus.get(PayResultEvent::class.java).post(PayResultEvent(code))
    }

    fun observePayResultEvent(owner: LifecycleOwner, func: (t: PayResultEvent) -> Unit) {
        LiveEventBus.get(PayResultEvent::class.java).observe(owner, Observer(func))
    }

    fun postRefreshNoticeMsgEvent() {
        LiveEventBus.get(RefreshNoticeMsgEvent::class.java).post(RefreshNoticeMsgEvent(0))
    }

    fun observeRefreshNoticeMsgEvent(owner: LifecycleOwner, func: (t: RefreshNoticeMsgEvent) -> Unit) {
        LiveEventBus.get(RefreshNoticeMsgEvent::class.java).observe(owner, Observer(func))
    }

    fun postModifyUserInfoEvent(msg: String) {
        LiveEventBus.get(ModifyUserInfoEvent::class.java).post(ModifyUserInfoEvent(msg))
    }

    fun observeModifyUserInfoEvent(owner: LifecycleOwner, func: (t: ModifyUserInfoEvent) -> Unit) {
        LiveEventBus.get(ModifyUserInfoEvent::class.java).observe(owner, Observer(func))
    }

    fun postRefreshHisCompleteEvent(msg: String) {
        LiveEventBus.get(RefreshHisCompleteEvent::class.java).post(RefreshHisCompleteEvent(msg))
    }

    fun observeRefreshHisCompleteEvent(
        owner: LifecycleOwner,
        func: (t: RefreshHisCompleteEvent) -> Unit
    ) {
        LiveEventBus.get(RefreshHisCompleteEvent::class.java).observe(owner, Observer(func))
    }

    fun postAddCarCompleteEvent(msg: String) {
        LiveEventBus.get(AddCarCompleteEvent::class.java).post(AddCarCompleteEvent(msg))
    }

    fun observeAddCarCompleteEvent(owner: LifecycleOwner, func: (t: AddCarCompleteEvent) -> Unit) {
        LiveEventBus.get(AddCarCompleteEvent::class.java).observe(owner, Observer(func))
    }
    fun postReplyCompleteEvent(msg: String) {
        LiveEventBus.get(ReplyCompleteEvent::class.java).post(ReplyCompleteEvent(msg))
    }

    fun observeReplyCompleteEvent(owner: LifecycleOwner, func: (t: ReplyCompleteEvent) -> Unit) {
        LiveEventBus.get(ReplyCompleteEvent::class.java).observe(owner, Observer(func))
    }

    fun postWxPayCompleteEvent(msg: String) {
        LiveEventBus.get(WxPayCompleteEvent::class.java).post(WxPayCompleteEvent(msg))
    }

    fun observeWxPayCompleteEvent(owner: LifecycleOwner, func: (t: WxPayCompleteEvent) -> Unit) {
        LiveEventBus.get(WxPayCompleteEvent::class.java).observe(owner, Observer(func))
    }

    fun postWorkOrderRefreshEvent(msg: String) {
        LiveEventBus.get(WorkOrderRefreshEvent::class.java).post(WorkOrderRefreshEvent(msg))
    }

    fun postWorkOrderDetailRefreshEvent(msg: String) {
        LiveEventBus.get(WorkOrderDetailRefreshEvent::class.java)
            .post(WorkOrderDetailRefreshEvent(msg))
    }

    fun observeWorkOrderDetailRefreshEvent(
        owner: LifecycleOwner,
        func: (t: WorkOrderDetailRefreshEvent) -> Unit
    ) {
        LiveEventBus.get(WorkOrderDetailRefreshEvent::class.java).observe(owner, Observer(func))
    }

    fun postAuditRefreshEvent(msg: String) {
        LiveEventBus.get(AuditRefreshEvent::class.java).post(AuditRefreshEvent(msg))
    }

    fun postDispatchRefreshEvent(msg: String) {
        LiveEventBus.get(DispatchRefreshEvent::class.java).post(DispatchRefreshEvent(msg))
    }

    fun observeScanResultEvent(owner: LifecycleOwner, func: (t: ScanResultEvent) -> Unit) {
        LiveEventBus.get(ScanResultEvent::class.java).observe(owner, Observer(func))
    }

    fun postMembersSelectEvent(value: List<MembersBean>) {
        LiveEventBus.get(MembersSelectEvent::class.java).post(MembersSelectEvent(value))
    }

    fun observeMembersSelectEvent(owner: LifecycleOwner, func: (t: MembersSelectEvent) -> Unit) {
        LiveEventBus.get(MembersSelectEvent::class.java).observe(owner, Observer(func))
    }
    fun postCommunityRefreshEvent(value:String){
        LiveEventBus.get(CommunityRefreshEvent::class.java).post(CommunityRefreshEvent(value))
    }
    fun observeCommunityRefreshEvent(owner: LifecycleOwner, func: (t: CommunityRefreshEvent) -> Unit){
        LiveEventBus.get(CommunityRefreshEvent::class.java).observe(owner, Observer(func))
    }
    fun postBulletinRefreshEvent(value:String){
        LiveEventBus.get(BullentinRefreshEvent::class.java).post(BullentinRefreshEvent(value))

    }
    fun observeBulletinRefreshEvent(owner: LifecycleOwner, func: (t: BullentinRefreshEvent) -> Unit){
        LiveEventBus.get(BullentinRefreshEvent::class.java).observe(owner, Observer(func))
    }

    fun observeWorkOrderRefreshEvent(
        owner: LifecycleOwner,
        func: (t: WorkOrderRefreshEvent) -> Unit
    ) {
        LiveEventBus.get(WorkOrderRefreshEvent::class.java).observe(owner, Observer(func))
    }

    fun observeAuditRefreshEvent(owner: LifecycleOwner, func: (t: AuditRefreshEvent) -> Unit) {
        LiveEventBus.get(AuditRefreshEvent::class.java).observe(owner, Observer(func))
    }

    fun observeDispatchRefreshEvent(
        owner: LifecycleOwner,
        func: (t: DispatchRefreshEvent) -> Unit
    ) {
        LiveEventBus.get(DispatchRefreshEvent::class.java).observe(owner, Observer(func))
    }

    fun postScanResultEvent(result: String) {
        LiveEventBus.get(ScanResultEvent::class.java).post(ScanResultEvent(result))
    }

    // 领用物品
    fun postAddChoosedSortEvent(sortBean: SortBean?) {
        LiveEventBus.get(AddChoosedSortEvent::class.java).post(AddChoosedSortEvent(sortBean))
    }

    fun observeAddChoosedSortEvent(
        owner: LifecycleOwner,
        func: (t: AddChoosedSortEvent) -> Unit
    ) {
        LiveEventBus.get(AddChoosedSortEvent::class.java).observe(owner, Observer(func))
    }

    fun postAddPurchaseSortEvent(bean: PurchaseOrderBean?) {
        LiveEventBus.get(AddPurchaseSortEvent::class.java).post(AddPurchaseSortEvent(bean))
    }

    fun observeAddPurchaseSortEvent(
        owner: LifecycleOwner,
        func: (t: AddPurchaseSortEvent) -> Unit
    ) {
        LiveEventBus.get(AddPurchaseSortEvent::class.java).observe(owner, Observer(func))
    }

    // 处置在用资产添加
    fun postAddAssetPurchaseSortEvent(data: List<SortBean>?) {
        LiveEventBus.get(AddAssetPurchaseSortEvent::class.java).post(AddAssetPurchaseSortEvent(data))
    }
    fun observeAddAssetPurchaseSortEvent(
        owner: LifecycleOwner,
        func: (t: AddAssetPurchaseSortEvent) -> Unit
    ) {
        LiveEventBus.get(AddAssetPurchaseSortEvent::class.java).observe(owner, Observer(func))
    }

    // 处置在用资产添加
    fun postAddAssetHanldeFacilityEvent(data: List<AssetHandleFacilityBean>?) {
        LiveEventBus.get(AddAssetHanldeFacilityEvent::class.java).post(AddAssetHanldeFacilityEvent(data))
    }
    fun observeAddAssetHanldeFacilityEvent(
        owner: LifecycleOwner,
        func: (t: AddAssetHanldeFacilityEvent) -> Unit
    ) {
        LiveEventBus.get(AddAssetHanldeFacilityEvent::class.java).observe(owner, Observer(func))
    }
    fun postAddAssetHanldeSortEvent(data: List<AssetHandleSortBean>?,handleType:String?,manageMode:Int?) {
        LiveEventBus.get(AddAssetHanldeSortEvent::class.java).post(AddAssetHanldeSortEvent(data, handleType,manageMode))
    }
    fun observeAddAssetHanldeSortEvent(
        owner: LifecycleOwner,
        func: (t: AddAssetHanldeSortEvent) -> Unit
    ) {
        LiveEventBus.get(AddAssetHanldeSortEvent::class.java).observe(owner, Observer(func))
    }
    fun postAddAssetHanldeSortSelectEvent(data: HashMap<String,Int>?) {
        LiveEventBus.get(AddAssetHanldeSortSelectEvent::class.java).postOrderly(AddAssetHanldeSortSelectEvent(data))
    }
    fun observeAddAssetHanldeSortSelectEvent(
        owner: LifecycleOwner,
        func: (t: AddAssetHanldeSortSelectEvent) -> Unit
    ) {
        LiveEventBus.get(AddAssetHanldeSortSelectEvent::class.java).observeSticky(owner, Observer(func))
    }
    // tab页
    fun postGoToTabEvent(index: Int?) {
        LiveEventBus.get(GoToTabEvent::class.java).post(GoToTabEvent(index))
    }
    fun observeGoToTabEvent(
        owner: LifecycleOwner,
        func: (t: GoToTabEvent) -> Unit
    ) {
        LiveEventBus.get(GoToTabEvent::class.java).observe(owner, Observer(func))
    }

    // tab页
    fun postAssetResultReturnEvent(index: Int?) {
        LiveEventBus.get(AssetResultReturnEvent::class.java).post(AssetResultReturnEvent(index))
    }
    fun observeAssetResultReturnEvent(
        owner: LifecycleOwner,
        func: (t: AssetResultReturnEvent) -> Unit
    ) {
        LiveEventBus.get(AssetResultReturnEvent::class.java).observe(owner, Observer(func))
    }
    fun postToMoreEvent(){
        LiveEventBus.get(ToMoreEvent::class.java).post(ToMoreEvent(1))
    }

    fun observeToMoreEvent(owner: LifecycleOwner, func: (t: ToMoreEvent) -> Unit){
        LiveEventBus.get(ToMoreEvent::class.java).observe(owner, Observer(func))

    }

    // 扫码结果
    fun postScanResultReturnEvent(result: String?) {
        LiveEventBus.get(ScanResultReturnEvent::class.java).post(ScanResultReturnEvent(result))
    }
    fun observeScanResultReturnEvent(
        owner: LifecycleOwner,
        func: (t: ScanResultReturnEvent) -> Unit
    ) {
        LiveEventBus.get(ScanResultReturnEvent::class.java).observe(owner, Observer(func))
    }

    // 盘点结果
    fun postInventoryResultReturnEvent(tab: Int? , mark: Int?) {
        LiveEventBus.get(InventoryResultReturnEvent::class.java).post(InventoryResultReturnEvent(tab, mark))
    }
    fun observeInventoryResultReturnEvent(
        owner: LifecycleOwner,
        func: (t: InventoryResultReturnEvent) -> Unit
    ) {
        LiveEventBus.get(InventoryResultReturnEvent::class.java).observe(owner, Observer(func))
    }

    // 盘盈登记
    fun postRegisterResultReturnEvent(result: Int?) {
        LiveEventBus.get(RegisterResultReturnEvent::class.java).post(RegisterResultReturnEvent(result))
    }
    fun observeRegisterResultReturnEvent(
        owner: LifecycleOwner,
        func: (t: RegisterResultReturnEvent) -> Unit
    ) {
        LiveEventBus.get(RegisterResultReturnEvent::class.java).observe(owner, Observer(func))
    }

    // 盘点查询
    fun postSearchParamReturnEvent(param: String?) {
        LiveEventBus.get(SearchParamReturnEvent::class.java).post(SearchParamReturnEvent(param))
    }
    fun observeSearchParamReturnEvent(
        owner: LifecycleOwner,
        func: (t: SearchParamReturnEvent) -> Unit
    ) {
        LiveEventBus.get(SearchParamReturnEvent::class.java).observe(owner, Observer(func))
    }

    // 盘点列表刷新
    fun postInventoryHomeReturnEvent(result: Int?) {
        LiveEventBus.get(InventoryHomeReturnEvent::class.java).post(InventoryHomeReturnEvent(result))
    }
    fun observeInventoryHomeReturnEvent(
        owner: LifecycleOwner,
        func: (t: InventoryHomeReturnEvent) -> Unit
    ) {
        LiveEventBus.get(InventoryHomeReturnEvent::class.java).observe(owner, Observer(func))
    }

    // 拍照上传结果
    fun postUploadImgReturnEvent(result: Int?) {
        LiveEventBus.get(UploadImgReturnEvent::class.java).post(UploadImgReturnEvent(result))
    }
    fun observeUploadImgReturnEvent(
        owner: LifecycleOwner,
        func: (t: UploadImgReturnEvent) -> Unit
    ) {
        LiveEventBus.get(UploadImgReturnEvent::class.java).observe(owner, Observer(func))
    }

}